/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lt.ntec.danblog.server.core.model.objectify;

import com.google.inject.Inject;
import com.google.inject.Injector;
import java.util.Set;
import lt.ntec.danblog.server.core.GuiceFactory;
import lt.ntec.danblog.server.core.model.TagDAO;
import lt.ntec.danblog.server.core.model.Taggable;

/**
 *
 * @author Tadas
 */
class ProxyFactory {

    private static Injector INJECTOR;
    @Inject
    private TagDAO tagDAO;
    private static ProxyFactory PROXY_FACTORY;

    private ProxyFactory() {
    }

    /**
     * This Singleton approach is needed because PostLoad action cannon access
     * dependency injection
     *
     * @return
     */
    public static ProxyFactory getInstance() {

        if (PROXY_FACTORY != null) {
            return PROXY_FACTORY;
        }

        ProxyFactory proxyFactory =
                new ProxyFactory();
        INJECTOR = GuiceFactory.getInjector();

        INJECTOR.injectMembers(proxyFactory);

        PROXY_FACTORY = proxyFactory;

        return PROXY_FACTORY;
    }

    public static void setInjector(Injector injector) {
        ProxyFactory.INJECTOR = injector;
    }

    public Set<Taggable> getParentListProxy(ObjectifyTag tag) {
        return TagParentListProxy.newInstance(tag, tagDAO);
    }
}
